<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="https://cdn.staticfile.org/vue/2.6.14/vue.js"></script>
    <script src="https://cdn.staticfile.org/vuex/3.6.2/vuex.js"></script>
  </head>
  <body>
    <div id="app">
      root {{msg}}
      <parent></parent>
      <hr />
      <parent></parent>
    </div>
    <script>
      const { mapState } = Vuex;
      const store = new Vuex.Store({
        state: {
          msg: "hello world",
        },
        mutations: {
          updateMsg(state) {
            state.msg = Date.now();
          },
        },
      });

      Vue.component("parent", {
        template: `
        <div>
          parent
          <child></child>
        </div>
        `,
      });
      Vue.component("child", {
        template: `
        <div @click='$store.commit("updateMsg")'>
          child {{msg}}
        </div>
        `,
        data: function () {
          return {
            count: 1,
          };
        },
        computed: {
          ...mapState(["msg"]),
          n: function () {
            return this.count * this.count
          }
        },
      });

      const vm = new Vue({
        el: "#app",
        store,
        methods: {},
        computed: mapState(["msg"]),
      });
    </script>
  </body>
</html>
